/*-----------------------------------------------------------------------------------*/
/* Nuvoton Technology Corporation confidential                                       */
/*                                                                                   */
/* Copyright (c) 2008 by Nuvoton Technology Corporation                              */
/* All rights reserved                                                               */
/*                                                                                   */
/*-----------------------------------------------------------------------------------*/
#include "nuc900_reg.h"
#include "wblib.h"
#include "fmi.h"

#ifdef DMAC_SCATTER_GETTER

DMAC_DESC_T DMAC_DESC[32];

INT dmacSetDescriptor(UINT32 uaddr, UINT32 ucount)
{
	UINT32 volatile paddr, loop, remcount;
	int volatile i=0;

	loop = ucount / 8;

	paddr = uaddr;
	for (i=0; i<loop; i++, paddr+=0x1000)
	{
		DMAC_DESC[i].uPhyAddress = sysGetPhyPageAddr(paddr);
		DMAC_DESC[i].uSectorCount = 8;
	}

	remcount = ucount % 8;
	if (remcount != 0)
	{
		DMAC_DESC[i].uPhyAddress = sysGetPhyPageAddr(paddr);
		DMAC_DESC[i].uSectorCount = remcount|0x80000000;
	}
	else if (loop > 0)
		DMAC_DESC[i-1].uSectorCount = DMAC_DESC[i-1].uSectorCount|0x80000000;
	else
		return Fail;
	
	sysFlushCache(D_CACHE);
	return Successful;
}

#endif


